-- 15
function ccR_Mage_Presence_of_Mind(specNumber)
	if specNumber == nil then specNumber = ccrSpec() end
	local vUseTalent = ccRS["Mage_" .. specNumber .. "_UsePresenceOfMind"]
	if vUseTalent
	and ccrPlayerHasTalent(PRESENCE_OF_MIND)
	and ccrSpellIsReady(PRESENCE_OF_MIND)
	then
		ccrCast(PRESENCE_OF_MIND)
		return
	end
	return
end

function ccR_Mage_Ice_Floes(specNumber)
	if specNumber == nil then specNumber = ccrSpec() end
	local vUseTalent = ccRS["Mage_" .. specNumber .. "_UseIceFloes"]
	if vUseTalent
	and ccrPlayerHasTalent(ICE_FLOES)
	and ccrSpellIsReady(ICE_FLOES)
	and ccrPlayerIsInCombat()
	and ccrPlayerIsMoving()
	and not ccrPlayerHasBuff(ICE_FLOES)
	and Target and Target:Exists() and not Target:IsDead()
	then
		ccrCast(ICE_FLOES)
		return
	end
	return
end

-- 30
function ccR_Mage_Temporal_Shield(specNumber)
	if specNumber == nil then specNumber = ccrSpec() end
	local vUseAbility = ccRS["Mage_" .. specNumber .. "_UseTemporalShield"]
	if vUseAbility
	and ccrPlayerHasTalent(TEMPORAL_SHIELD)
	and ccrSpellIsReady(TEMPORAL_SHIELD)
	and not ccrPlayerHasBuff(TEMPORAL_SHIELD)
	and #tblPGetMeleeEnemies > 0
	then
		if ccrPlayerIsCastingOrChanneling() then SpellStopCasting() end
		ccrCast(TEMPORAL_SHIELD)
		return
	end
	return
end

vccR_Last_Ice_Barrier_Check = 0.1
function ccR_Mage_Ice_Barrier(specNumber)
	if specNumber == nil then specNumber = ccrSpec() end
	local vUseAbility = ccRS["Mage_" .. specNumber .. "_UseIceBarrier"]
	if vUseAbility
	and ccrPlayerHasTalent(ICE_BARRIER)
	and ccrSpellIsReady(ICE_BARRIER)
	and not ccrPlayerHasBuff(ICE_BARRIER)
	and (GetTime()-vccR_Last_Ice_Barrier_Check) > 0.50
	then
		if # tblPGetMeleeEnemies >= 1 then
			for x = 1, # tblPGetMeleeEnemies do
				local obj = tblPGetMeleeEnemies[x]
				if obj
				and obj:Exists()
				and (obj:GetTarget():Exists() and obj:GetTarget():GetName() == ccrPlayerName())
				then
					if ccrPlayerIsCastingOrChanneling() then SpellStopCasting() end
					ccrCast(ICE_BARRIER)
					return
				end
			end
		end
		vccR_Last_Ice_Barrier_Check = GetTime()
	end
	return
end

-- 45
function ccR_Mage_Ring_of_Frost(specNumber)
	if specNumber == nil then specNumber = ccrSpec() end
	local vUseTalent = ccRS["Mage_" .. specNumber .. "_UseRingOfFrost"]
	local vEnemyCount = ccRS["Mage_" .. specNumber .. "_RingOfFrostCount"]
	if vUseTalent
	and ccrPlayerHasTalent(RING_OF_FROST)
	and ccrSpellIsReady(RING_OF_FROST)
	and ccrValidTarget()
	and ccrTargetCount(10) >= vEnemyCount
	then
		ccrCast(RING_OF_FROST)
		if SpellIsTargeting() == 1 then CastAtLocation(Target:GetLocation()) end
		return
	end
end

vccR_Last_Ice_Ward_Check = 0.1
function ccR_Mage_Ice_Ward(specNumber)
	if specNumber == nil then specNumber = ccrSpec() end
	local vUseTalent = ccRS["Mage_" .. specNumber .. "_UseIceWard"]
	if ccrPlayerHasTalent(ICE_WARD)
	and ccrSpellIsReady(ICE_WARD)
	and not ccrPlayerHasBuff(ICE_WARD)
	and ccrPlayerIsInCombat()
	and #tblPGetNearbyEnemies > 0
	and (GetTime()-vccR_Last_Ice_Ward_Check) > 0.50
	then
		if # tblPGetNearbyEnemies >= 1 then
			for x = 1, # tblPGetNearbyEnemies do
				local obj = tblPGetNearbyEnemies[x]
				if obj
				and obj:Exists()
				and (obj:GetTarget():Exists() and obj:GetTarget():GetName() == ccrPlayerName())
				then
					ccrCast(ICE_WARD, "player")
					return
				end
			end
		end
		vccR_Last_Ice_Ward_Check = GetTime()
		return
	end
end

function ccR_Mage_Frostjaw(specNumber)
	if specNumber == nil then specNumber = ccrSpec() end
	local vUseTalent = ccRS["Mage_" .. specNumber .. "_UseFrostjaw"]
	if ccrPlayerHasTalent(FROSTJAW)
	and ccrSpellCanAttack(FROSTJAW)
	and not ccrTargetIsBoss()
	then
		ccrCastAttack(FROSTJAW)
		return
	end
	return
end

-- 60
function ccR_Mage_Cold_Snap(specNumber)
	if specNumber == nil then specNumber = ccrSpec() end
	local vUseTalent = ccRS["Mage_" .. specNumber .. "_UseColdSnap"]
	if vUseTalent
	and ccrPlayerHasTalent(COLD_SNAP)
	and ccrSpellIsReady(COLD_SNAP)
	and ((onCD(ICE_BLOCK) and onCD(FROST_NOVA) and onCD(CONE_OF_COLD)) or (ccrPlayerHealth() <= 30))
	then
		ccrCast(COLD_SNAP)
		return
	end
	return
end

-- 75
function ccR_Mage_Nether_Tempest(specNumber)
	if specNumber == nil then specNumber = ccrSpec() end
	local vUseTalent = ccRS["Mage_" .. specNumber .. "_UseNetherTempest"]
	if vUseTalent
	and ccrPlayerHasTalent(NETHER_TEMPEST)
	and ccrSpellIsReady(NETHER_TEMPEST)
	then
		-- Debuff our Target
		if ccrValidTarget()
		and not ccrTargetHasMyDebuff(NETHER_TEMPEST)
		and ccrSpellCanAttack(NETHER_TEMPEST)
		then
			ccrCastAttack(NETHER_TEMPEST)
		end
		-- Debuff All Tapped
		if # tblPGetNearbyEnemies >= 1 then
			for x = 1, # tblPGetNearbyEnemies do
				local obj = tblPGetNearbyEnemies[x]
				if obj
				and obj:Exists()
				and (obj:IsTappedByPlayer() or (obj:GetTarget():Exists() and obj:GetTarget():GetName() == ccrPlayerName()))
				and obj:InLineOfSight()
				and not ccrUnitHasMyDebuff(obj, NETHER_TEMPEST)
				and not ccrIgnoreNPCWithAura(obj)
				and tContains(tblAutoTargetIgnoreList, ccrNPCID(obj:GetGUID())) == nil
				then
					local vBomb = GetSpellInfo(NETHER_TEMPEST)
					obj:CastSpellByName(vBomb)
					return
				end
			end
		end	
	end	
end

function ccR_Mage_Living_Bomb(specNumber)
	if specNumber == nil then specNumber = ccrSpec() end
	local vUseTalent = ccRS["Mage_" .. specNumber .. "_UseLivingBomb"]
	if vUseTalent
	and ccrPlayerHasTalent(LIVING_BOMB)
	and ccrSpellIsReady(LIVING_BOMB)
	then
		if # tblPGetNearbyEnemies >= 1 then
			for x = 1, # tblPGetNearbyEnemies do
				local obj = tblPGetNearbyEnemies[x]
				if obj
				and obj:Exists()
				and (obj:IsTappedByPlayer() or (obj:GetTarget():Exists() and obj:GetTarget():GetName() == ccrPlayerName()))
				and obj:InLineOfSight()
				and not ccrUnitHasMyDebuff(obj, LIVING_BOMB)
				and not ccrIgnoreNPCWithAura(obj)
				and tContains(tblAutoTargetIgnoreList, ccrNPCID(obj:GetGUID())) == nil
				then
					local vBomb = GetSpellInfo(LIVING_BOMB)
					obj:CastSpellByName(vBomb)
					return
				end
			end
		end	
	end	
end

function ccR_Mage_Frost_Bomb(specNumber)
	if specNumber == nil then specNumber = ccrSpec() end
	local vUseTalent = ccRS["Mage_" .. specNumber .. "_UseFrostBomb"]
	if vUseTalent
	and ccrPlayerHasTalent(FROST_BOMB)
	and ccrSpellCanAttack(FROST_BOMB)
	and Target and Target:Exists() and Player:IsFacing(Target)
	then
		ccrCastAttack(FROST_BOMB)
		return
	end
	return
end

-- 90
function ccR_Mage_Rune_of_Power()
end

function ccR_Mage_Incanters_Ward()
end